package com.help.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.help.model.PushMessage;
import com.help.tools.JDBConnection;



public class PushMessageDao {
	private static PushMessageDao instance = null;
	private JDBConnection connection = null; // 定义数据库连接类JDBConnection 对象并赋值为null

	private PushMessageDao() {
		connection = new JDBConnection();
	}

	/**
	 * 返回一个PushMessageDao实例,单例模式
	 * 
	 * @return
	 */
	public static PushMessageDao getInstance() {
		if (instance == null) {
			instance = new PushMessageDao();
		}
		return instance;
	}
    /**
     * 保存一个PushMessage对象
     * ***/
	public  boolean savePushMessage(PushMessage pushMessage){
		String sql;
		if (connection == null) {
			connection = new JDBConnection();// 将JDBC对象进行实例化
		}
		sql="insert into tb_pushmessage(`DeviceTokens`,`Latitude`,`Lontitude`,`Addr`,`PushTime`,`Message`,`hasPushed`)  values ('"+
			pushMessage.getDeviceTokens()+"','"+pushMessage.getLatitude()+"','"+pushMessage.getLontitude()+"','"+pushMessage.getAddr()+
			"','"+pushMessage.getPushTime()+"','"+pushMessage.getMessage()+"','"+(pushMessage.isHasPushed()? 1:0)+"')";
		System.out.println(sql);
		boolean flag=connection.executeUpdate(sql);
		connection.closeConnection();
		return flag;
	}

   
}
